﻿using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;

namespace NewRetail.Application.Core.SingleStore
{
    public class SingleStoreMiddleware : IMiddleware, ITransientDependency
    {
        private readonly ISingleStoreService singleStoreService;
        public SingleStoreMiddleware(ISingleStoreService singleStoreService)
        {
            this.singleStoreService = singleStoreService;
        }

        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            if (context.Request.Headers.TryGetValue("Warehouseid", out var storeId))
            {
                //拿到前端给的id，
                //这里理论上应该查库
                this.singleStoreService.SetCurrentStore(storeId);
            }

            await next.Invoke(context);
        }
    }
}
